﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JBeamLibrary.Tools;
using JBeamLibrary.VehicleParts.Elements;

namespace JBeamLibrary.VehicleParts.Collections
{
    public class GlowFunctionValueCollection : KeyedCollection<string, GlowFunctionValue>
    {
        #region CTORs

        /// <summary>Creates a new GlowFunctionValue collection</summary>
        public GlowFunctionValueCollection() { }

        /// <summary>Creates a new GlowFunctionValue collection</summary>
        /// <param name="values"></param>
        public GlowFunctionValueCollection(IEnumerable<GlowFunctionValue> values)
        {
            AddRange(values);
        }

        #endregion

        #region Methods

        public void Add(string name, float value)
        {
            Add(new GlowFunctionValue(name, value));
        }

        public void AddRange(IEnumerable<GlowFunctionValue> values)
        {
            foreach (var value in values)
                Add(value);
        }

        public void Remove(float value)
        {
            for (var i = 0; i < Count; i++)
            {
                var glowFunctionValue = this[i];
                if (!glowFunctionValue.Value.SafeEquals(value))
                    continue;

                RemoveAt(i);
                i--;
            }
        }

        #endregion

        #region KeyedCollection

        protected override string GetKeyForItem(GlowFunctionValue item)
        {
            return item.Name;
        }

        #endregion
    }
}
